<!DOCTYPE html>
<html>

<head lang="en">
    <title>攻略搜索结果</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/strategy.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css"/>
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <script>
        $(function () {
            //获取路径上的关键字
            var params=getParams();
            var keyword = decodeURIComponent(params.keyword);
            console.log(keyword);
            //获取分类值
            var type=params.type;
            console.log(type);

            //两个备用模块
            var a =$("#container").remove();
            var b=$("#pills-top").remove();
            //当前页
            var currentPage = 1;
            //总页数
            var pages = 1;
            //是否查询的标记
            var loading = false;
            //用户存储游记的数组容器
            var travelData=[];
            //查询方法
            function query() {
                //如果正在查询就不继续查了,退出
                if (loading) {
                    return;
                }
                //设置为查询状态
                loading = true;
                if(type==1){
                    $("#pills-tabContent").append(b)
                    //全部攻略
                    $.get('/strategies/' + keyword + '/search', {currentPage: currentPage}, function (data) {
                        console.log(data);
                        if(data.total!=0){
                            //把查询的数据放到容器中
                            $.merge(travelData,data.list);
                            //将容器封装到属性为list的对象中
                            var json = {list:travelData};
                            //渲染数据
                            $("#pills-top").renderValues(json, {
                                getHref: getHref
                            })
                        }else{
                           $(document).dialog({
                                titleText: "温馨提示",
                                content: "找不到与关键字相匹配的游记内容",
                               //onClosed弹框关闭之后执行
                               onClosed:function () {
                                   //没有结果就返回上一级页面
                                   window.history.go(-1);
                               }
                            });
                        }
                        //当前页+1
                        currentPage++;
                        //总页数
                        pages = data.pages;
                        //设置为没有在查询  本次查询结束
                        loading = false;
                    }, "json");
                }else if(type==2){
                    $("ul").after(a)
                    //全部攻略
                    $.get('/travels/' + keyword + '/search', {currentPage: currentPage}, function (data) {
                        console.log(data);
                        if(data.total!=0){
                            //把查询的数据放到容器中
                            $.merge(travelData,data.list);
                            //将容器封装到属性为list的对象中
                            var json = {list:travelData};
                            //渲染数据
                            $("#allTravels").renderValues(json, {
                                getHref: getHref
                            })
                        }else{
                            $(document).dialog({
                                titleText: "温馨提示",
                                content: "找不到与关键字相匹配的游记内容",
                                //onClosed弹框关闭之后执行
                                onClosed:function () {
                                    //没有结果就返回上一级页面
                                    window.history.go(-1);
                                }
                            });
                        }
                        //当前页+1
                        currentPage++;
                        //总页数
                        pages = data.pages;
                        //设置为没有在查询  本次查询结束
                        loading = false;
                    }, "json");
                }
            }

            query();

            //滚动页面 触发事件 翻页
            $(window).scroll(function () {
                //判断是否滚动到底部了  窗口的高度+文档滚动的高度 大于等于 文档的高度
                if ($(window).height() + $(document).scrollTop() + 1 >= $(document).height()) {
                    //如果当前页大于总页数就不查询了
                    if (currentPage <= pages) {
                        //查询
                        query();
                    } else {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '亲,已经到底了',
                            autoClose: 1500,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    }
                }
            });

            //给上一页a标签绑定点击事件
            $("#12").click(function () {
                //返回上一级页面
                window.history.go(-1);
            })
        })
    </script>

</head>

<body>


<div class="search-head">
    <div class="row nav-search">
        <div class="col-1">
            <a id="12">
                <span><i class="fa fa-chevron-left fa-2x"></i></span>
            </a>
        </div>
        <div>
            <a class="nav-link active show" data-toggle="pill" href="#pills-top">
                <span style="font-size: 25px ;color: white">搜索结果</span>
            </a>
        </div>
    </div>
</div>

<ul class="nav nav-pills nav-justified border border-left-0 border-top-0 border-right-0" id="pills-tab" role="tablist"></ul>

<div class="tab-content" id="pills-tabContent">
    <div class="tab-pane fade active show" id="pills-top">
        <div class="container commend" render-loop="list">
            <a render-fun="getHref" render-key="list.id" data-url="/strategyCatalogs.html?id=">
                <img render-src="list.coverUrl">
                <p render-html="list.title"></p>
            </a>
        </div>
    </div>
</div>


<div class="container">
    <div id="allTravels">
        <div render-loop="list">
            <div class="row detail">
                <div class="col-5">
                    <!--render-key是指值从哪里来,render-fun是指渲染的时候要调用的方法名字-->
                    <a render-fun="getHref" render-key="list.id" data-url="/travelContent.html?id=" >
                        <h4 render-html="list.title" ></h4>
                    </a>
                    <p>
                        <!--render-key是指值从哪里来,render-fun是指渲染的时候要调用的方法名字-->
                    <div class="commet-head"></div>
                    <a render-fun="getHref" render-key="list.author.id" data-url="/userProfiles.html?id=" >
                        <img class="rounded-circle head-img" width="15%" render-src="list.author.headImgUrl">
                        <span render-html="list.author.nickName"></span>
                    </a>
                    <br/>
                    <span class="addr" render-html="list.place.name" ></span>

                    </p>
                    <!--<p>
                        <i class="fa fa-eye fa-fw"></i>
                        <span>0</span>
                        <i class="fa fa-commenting fa-fw"></i>
                        <span>0</span>
                    </p>-->
                </div>
                <div class="col-7 bigimg" >
                    <a render-fun="getHref" render-key="list.id" data-url="/travelContent.html?id=" >
                        <img render-src="list.coverUrl" width="100%"; height="auto";>
                    </a>
                </div>
            </div>
        </div>
    </div>
    <hr>
</div>
</body>
</html>